<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>文章列表--layui后台管理模板 2.0</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="/css/public.css" media="all" />

	<link rel="stylesheet" href="/layui/css/formSelects-v4.css">
	<script src="/layui/layui.js"></script>
	<script src="/js/jquery.min.js"></script>
	<script type="text/javascript" src="/layui/layui.js"></script>

	<script src="/js/config.js"></script>
	<script type="text/javascript" src="/js/ChinesePY.js"></script>

</head>
<body class="childrenBody">

<div class="layui-row">

	<table class="layui-table" lay-filter="roleTable" lay-data="{id:'roleTable',text:{none:'没有要显示的数据'},url:'http://localhost:8888/bli/list',page:true,even:true,defaultToolbar:['filter', 'print', 'exports']}">
		<thead>
		<th lay-data="{field:'disoddid'}">病单号</th>
		<th lay-data="{field:'rname'}">病人</th>
		<th lay-data="{field:'retime'}">上报时间</th>
		<th lay-data="{field:'username'}">医生</th>
		<!--<th lay-data="{field:'yiqi'}">仪器</th>-->

		<th lay-data="{toolbar: '#barDemo'}">操作</th>
		</thead>
	</table>
</div>

<script>
    var table,select ;

    layui.config({
        base: '/layui/'
    }).extend({
        formSelects: 'formSelects-v4'
    });
    layui.use(['form','table','formSelects','laytpl'], function() {
        var form = layui.form;
        table = layui.table;
        select = layui.formSelects;
        var laytpl = layui.laytpl;

        form.render();
        //监听单选按钮事件
        table.on('radio(roleTable)', function (obj) {
            id = obj.data.id;
            loadPerTree(obj.data.id);
        });

        //头工具栏事件
        table.on('toolbar(roleTable)', function(obj){
            switch(obj.event){
                case 'batchDelete': //批量删除
                    //获取选中行
                    var checkStatus = table.checkStatus(obj.config.id);
                    var data = checkStatus.data;
                    if(data.length == 0){
                        layer.msg('请选择要删除的数据行');
                        return;
                    }
                    layer.confirm("确定要删除选中的数据吗？",function (index) {
                        var p = "?";
                        for(let role of data){
                            p += `id=${role.id}&`;
                        }

                        $.post(`http://localhost:8888/bli/batchDelete${p}`,d => {
                            layer.close(index);
                            table.reload("roleTable");
                        });
                    })
                    break;
                case 'add':
                    $.get('add.html',function (data) {
                        layer.open({
                            title: '药典',
                            type:1,
                            anim:4,
                            skin:'layui-layer-molv',
                            area:'500px',
                            content:data,
                            maxmin:true,
                            btn : ['确定','取消'],
                            yes : function () {
                                var str = $("#add_bli_form").serialize();
                                $.post(`${new Config().base_url}/bli/adds`,str,function (data) {
                                    layer.close(layer.index);
                                    table.reload('roleTable');
                                });

                            }
                        });
                    });
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选': '未全选');
                    break;
            };
        });
        //监听行内的工具条
        table.on('tool(roleTable)', function (obj) {
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）

            if (layEvent === 'del') { //删除
                layer.confirm('真的删除行么', function (index) {
                    layer.close(index);
                    $.post("http://localhost:8888/bli/delete",{id: data.id}, function (d) {
                        table.reload("roleTable", {
                            page: {
                                curr: 1
                            }
                        });
                    });
                });
            } else if (layEvent === 'edit') {//TODO 编辑

                $.get('add.html',function (s) {
                    layer.open({
                        type : 1,
                        title : '录入数据',
                        area:'800px',
                        content:s,
                        btn : ['确定','取消'],
                        success:function(){
                            //对表单回填数据
                            data.locked = data.locked == 0 ? null : data.locked;
                            form.val('roleForm',data);
                            var t =setInterval(function () {
                                console.log("waiting....");

                            },100)

                        },
                        yes : function () {
                            var str = $("#add_bli_form").serialize();
                            $.post(`${new Config().base_url}/bli/updatess`,str,function (data) {
                                layer.close(layer.index);
                                table.reload('roleTable');

                            })

                        }
                    })
                })

            } else if (layEvent === 'detail') { //TODO 查看详情

            }
        });
    });

</script>


<script type="text/html" id="barDemo">

	<a lay-event="edit">录入<i class="layui-icon layui-icon-edit"></i></a>

</script>
</body>
</html>